﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Diagnostics;
using System.Threading;
using System.Collections;

namespace SampleWinProject
{
    public partial class frmProference : Form
    {
         
        public frmProference()
        {
            InitializeComponent();
        }

        private void frmProference_Load(object sender, EventArgs e)
        {
            PerformanceCounterCategory[] myCat2;
            myCat2 = PerformanceCounterCategory.GetCategories();
            listBox1.DataSource = myCat2;
            listBox1.DisplayMember = "CategoryName";
            
            //for (int i = 0; i < myCat2.Length; i++)
            //{
            //    richTextBox1.AppendText(myCat2[i].CategoryName.ToString());
            //    richTextBox1.AppendText("\r\n");
            //}
           var persons = new[] {
    new Person { Name = "Orochi" },
    new Person { Name = "Blinda" },
    new Person { Name = "Ninicat" }
};

            var result = from person in persons where person.Name.IndexOf("o") >-1
    select new { Name = person.Name};

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            int oddNumbers = numbers.Count(n => n % 2 == 1);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            PerformanceCounterCategory category = (PerformanceCounterCategory)listBox1.SelectedItem;
            listBox2.Items.Add("Type：" + category.CategoryType.ToString());
            listBox2.Items.Add("Name：" + category.CategoryName);
            listBox2.Items.Add("MachineName：" +category.MachineName);
            foreach(string name in  category.GetInstanceNames())
            {
                listBox2.Items.Add("InstanceName：" +name);
                foreach(PerformanceCounter counter in category.GetCounters(name))
                {
                    listBox2.Items.Add("CategoryName：" + counter.CategoryName);
                    listBox2.Items.Add("CounterName：" + counter.CounterName);
                    listBox2.Items.Add("CounterType：" + counter.CounterType.ToString());
                    listBox2.Items.Add("Value：" + counter.NextValue().ToString());
                }
            }
            
        }
    }

    public class Person:IEnumerable
    {
        public string Name;
        private System.Collections.Generic.List<string> list = new List<string>();

        public void Add(string person)
        {
            list.Add(person);
        }

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return list.GetEnumerator();
        }

        #endregion
    }
}
